#coding:utf-8
import os
import re

clientBranch = os.environ['CLIENT_BRANCH']
apiBranch = os.environ['API_BRANCH']

#retrieve version code
file = os.popen("aapt dump badging app/build/outputs/apk/app-debug.apk")
line = file.readline()
print line
line = versionNameKey.readline()
temp = line.split(" ")
print temp
temp = temp[3]
print temp
temp = temp.split("=")
print temp
versionName = temp[1]
apkName = "Android_%s_%s_B_%s_A_%s.apk"%(versionName,os.environ['BUILD_TIMESTAMP'],clientBranch,apiBranch)

#rename app-debug.apk -> Android_XXX_XXX_B_XXX_A_XXX.apk
os.rename("app/build/outputs/apk/app-debug.apk","app/build/outputs/apk/"+apkName)

